package ex55.mm.flow.impound.quote.exchange.api;

import org.springframework.lang.Nullable;

public abstract class ExchangeException extends Exception {
    //确认的异常，可以自动进行一些操作
    public static class Reject extends ExchangeException {
        Reject(String message, Throwable cause) {
            super(message, cause);
        }

        @Override
        public boolean isReject() {
            return true;
        }
    }

    //不确定的异常，这里不能继续自动的操作
    public static class Uncertain extends ExchangeException {
        Uncertain(String message, Throwable cause) {
            super(message, cause);
        }

        @Override
        public boolean isReject() {
            return false;
        }
    }

    //错误信息
    private String message;
    private Throwable cause;

    ExchangeException(String message, Throwable cause) {
        this.message = message;
        this.cause = cause;
    }

    public static Reject newRejectException(String message, @Nullable Throwable cause) {
        return new Reject(message, cause);
    }

    public static Uncertain newUncertainException(String message, @Nullable Throwable cause) {
        return new Uncertain(message, cause);
    }

    @Override
    public String getMessage() {
        return message;
    }


    @Override
    public Throwable getCause() {
        return cause;
    }

    public abstract boolean isReject();

    @Override
    public String toString() {
        String clazzName = getClass().getName();
        String message = getLocalizedMessage();
        return (message != null) ? (clazzName + ": message: " + message) : clazzName;
    }
}
